package com.object.utils;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * map集合去空
 */
public class MapEmptyToolUtil
{
    public static ConcurrentHashMap<String, Object> emptyTool(Map<String, Object> map)
    {
        ConcurrentHashMap<String, Object> hashMap = new ConcurrentHashMap<>(map);
        deleteSystemPrem(hashMap);
        Set<String> keySet = hashMap.keySet();
        if (hashMap.size() != 0)
        {
            for (String key : keySet)
            {
                if (isNull(key) || isNull(String.valueOf(hashMap.get(key))))
                {
                    hashMap.remove(key, hashMap.get(key));
                }
            }
        }
        return hashMap;
    }

    public static boolean isNull(String str)
    {
        return str == null || str.equals("") || str.equals(" ") || str.equals("null") || str.equals("undefined");
    }

    private static void deleteSystemPrem(Map<String, Object> map)
    {
        isDelete(map, "pageSize");
        isDelete(map, "pageNum");
        isDelete(map, "totalNum");
    }

    private static void isDelete(Map<String, Object> map, String key)
    {
        if (map.containsKey(key))
        {
            map.remove(key);
        }
    }
}


